package io.renren.modules.gis_admin.controller;

import io.renren.common.annotation.LogOperation;
import io.renren.common.utils.Result;
import io.renren.common.validator.ValidatorUtils;
import io.renren.common.validator.group.AddGroup;
import io.renren.common.validator.group.DefaultGroup;
import io.renren.modules.gis_admin.dto.BasinSourceDTO;
import io.renren.modules.gis_admin.dto.SourceLastResultDTO;
import io.renren.modules.gis_admin.service.BasinSourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.io.IOException;
import java.util.List;
import javax.annotation.Resource;
import javax.validation.Valid;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 源数据
 *
 * @author Mark iu1340@163.com
 * @since 1.0.0 2023-09-21
 */
@RestController
@Api(tags = "源数据")
@RequestMapping("/source")
public class BasinSourceController {

  @Resource
  private BasinSourceService basinSourceService;

  @PostMapping
  @ApiOperation("保存")
  @LogOperation("保存")
  public Result<Long> save(@Valid @RequestBody BasinSourceDTO dto) throws IOException {
    ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
    return new Result<Long>().ok(basinSourceService.save(dto));
  }

  @GetMapping("list")
  @ApiOperation("列表")
  @LogOperation("列表")
  public Result<List<SourceLastResultDTO>> list() {
    return new Result<List<SourceLastResultDTO>>().ok(basinSourceService.list());
  }
}